﻿Namespace Catalog.Search
    Public Class SearchResponse
        Public Property PageCount As Integer
        Public Property PageSize As Integer
        Public Property Page As Integer
        Public Property Count As Integer
        Public Property CurrentQuery As Query
        Public Property NextQuery As Query
        Public Property Results As List(Of BaseObject)

        Public Sub New()
            Me.Results = New List(Of BaseObject)
        End Sub

        Public Shared Function FromBPObject(res As BPOSearchResponse) As SearchResponse
            If res Is Nothing Then Return Nothing
            Dim newResponse As New SearchResponse()

            With newResponse
                .PageCount = res.metadata.totalPages
                .PageSize = res.metadata.perPage
                .Page = res.metadata.page
                .Count = res.metadata.count
                .CurrentQuery = Nothing 'New Query()
                .NextQuery = Nothing 'New Query()

                For Each obj As BPOBase In res.results
                    Dim newObj As BaseObject = Nothing

                    Select Case obj.type
                        Case "release"
                            newObj = Release.FromBPObject(obj)
                        Case "label"
                            newObj = Label.FromBPObject(obj)
                        Case "artist"
                            newObj = Artist.FromBPObject(obj)
                        Case "chart"
                            newObj = Chart.FromBPObject(obj)
                        Case "track"
                            newObj = Track.FromBPObject(obj)
                        Case "genre"
                            newObj = Genre.FromBPObject(obj)
                        Case "remixer"

                        Case "djprofile"

                        Case "mix"
                            newObj = Mix.FromBPObject(obj)
                        Case "pack"
                            newObj = Pack.FromBPObject(obj)
                        Case Else
                    End Select

                    If newObj IsNot Nothing Then
                        .Results.Add(newObj)
                    End If
                Next
            End With

            Return newResponse
        End Function
    End Class
End Namespace